package ext.tianma.masschange.datautility;

import java.io.IOException;
import java.util.Locale;

import wt.part.LineNumber;
import wt.part.WTPart;
import wt.part.WTPartUsageLink;
import wt.session.SessionHelper;
import wt.util.WTException;
import wt.util.WTProperties;

import com.ptc.core.components.descriptor.ModelContext;
import com.ptc.core.components.factory.AbstractDataUtility;
import com.ptc.core.components.rendering.guicomponents.TextBox;

import ext.tianma.masschange.util.MassChangeUtil;

public class MassChangeLineNumberDataUtility extends AbstractDataUtility{
	
	private static String RESOURCE = "ext.tianma.masschange.resource.MassChangeResource";
	private static String CLASSNAME="";
	private static boolean VERBOSE = false;
	private static WTProperties wtProperties;
	private static Locale locale = null;

	static {

		try {
			CLASSNAME= MassChangeLineNumberDataUtility.class.getName();
			wtProperties = WTProperties.getLocalProperties();
			locale = SessionHelper.manager.getLocale();
			VERBOSE = wtProperties.getProperty("ext.tianma.masschange.datautility.verbose", false);
		}
		catch (IOException ioe) {
			ioe.printStackTrace();
		}catch (Throwable throwable) {
			throw new ExceptionInInitializerError(throwable);
		}
	}
	public MassChangeLineNumberDataUtility() {

	}
	  /**
	 *输出调试信息
	 */
	private static void outDebugInfo(String info) {
		if(VERBOSE)
			System.out.println(CLASSNAME+"......"+info);
	}	

	public Object getDataValue(String arg0, Object obj, ModelContext mc)
			throws WTException {
		
		TextBox gui =new TextBox();
		
		WTPart part = null;
		LineNumber linenumber=null;
		if(obj instanceof WTPartUsageLink) {
			WTPartUsageLink link = (WTPartUsageLink)obj;
			linenumber=link.getLineNumber();
			part = link.getUsedBy();
		} else if(obj instanceof WTPart) {
			part = (WTPart)obj;
		}
		
		
		if(MassChangeUtil.hasCA(part, mc)||MassChangeUtil.equalState(part, "UNDERREVIEW")||MassChangeUtil.equalState(part, "OBSOLESCENCE")) {
			return linenumber;			
		}
		String numberStr="1";
		if(linenumber!=null){
			
		numberStr=linenumber.toString().trim();;
		}
		gui.setValue(numberStr);
		gui.setName(numberStr);
		gui.setEditable(true);
		//gui.setId("numberStr");
		
		return gui;
	}

}
